<template>
  <div>
  <el-drawer title="修改菜单按钮" :visible.sync="dialogFormVisible" v-if="dialogFormVisible" size="25%">
      <el-form :inline="true" ref="formInline" :model="formInline" :rules="rules" :label-position="labelPosition" style="width: 120%" label-width="105px" class="demo-form-inline" size="small">

        <el-row>
          <el-col :span="24">
            <el-form-item label="按钮名称：" prop="name">
              <el-input v-model="formInline.name" :style="{width: '140%'}"  placeholder="请输入按钮名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="请求方式:" prop="method">
              <el-select :style="{width: '130%'}" v-model="formInline.method" clearable  placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.item"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="权限值:" prop="value">
              <el-input v-model="formInline.value" :style="{width: '140%'}" placeholder="请输入权限值"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="请求地址:" prop="api">
              <el-input v-model="formInline.api" :style="{width: '140%'}" placeholder="请输入组件地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
    </el-form>
    <div class="demo-drawer__footer" style="padding-left: 100px;">
      <el-button @click="resetForm('formInline')">取 消</el-button>
      <el-button type="primary" @click="submitEditForm('formInline')">修 改</el-button>
    </div>
  </el-drawer>
  </div>
</template>

<script>
  import { editMenuButtonData } from '@/api/menuButton'
  import { successMsg } from '@/utils/tools'
  export default {
    name: 'Edit',
    data() {
      return {
        dialogFormVisible: false,
        labelPosition:'right',
        options: [{
          value: 0,
          label: '查询(get)'
        }, {
          value: 1,
          label: '新增(post)'
        }, {
          value: 2,
          label: '编辑(put)'
        }, {
          value: 3,
          label: '删除(delete)'
        }, {
          value: 4,
          label: '单例(get)'
        }],
        formInline: {
          id:'',
          menu:'',
          name: '',
          method:'',
          value:'',
          api:'',
        },
        rules:{
          name:[
            { required: true, message: '请输入菜单按钮名称', trigger: 'blur' },
          ],
          method:[
            { required: true, message: '请选择按钮请求方式', trigger: 'change' },
          ],
          value:[
            { required: true, message: '请输入菜单按钮请求方式', trigger: 'blur' },
          ],
          api:[
            { required: true, message: '请输入菜单请求路径', trigger: 'blur' },
          ],
        }
      };
    },
    methods:{
      submitEditForm(formName) {
        if(this.formInline.method==4){
          this.formInline.method=0
        }
        this.$refs[formName].validate((valid) => {
          if(valid){
            editMenuButtonData(this.formInline).then(res=>{
              if(res.code===2000) {
                successMsg(res.msg)
                this.$emit('reloadTable')
                this.dialogFormVisible = false
              }
            })
          }else{
            return false;
          }
        });
      },
      resetForm(formName){
        this.$refs[formName].resetFields();
        this.dialogFormVisible = false
      },

    }
  }
</script>

<style>
  .main-select-el-tree .el-tree-node .is-current > .el-tree-node__content{font-weight: bold; color: #409eff;}
  .main-select-el-tree .el-tree-node.is-current > .el-tree-node__content{font-weight: bold; color: #409eff;}
</style>
